package com.trw.trp.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ModelDetail implements Cloneable {
	private long modelId;
	private List<ModelSection> sectionList = new ArrayList<ModelSection>();

	public long getModelId() {
		return modelId;
	}

	public void setModelId(long modelId) {
		this.modelId = modelId;
	}

	public List<ModelSection> getSectionList() {
		return sectionList;
	}

	public void setSectionList(List<ModelSection> sectionList) {
		this.sectionList = sectionList;
	}

	@Override
	public String toString() {
		return "ModelDetail [modelId=" + modelId + ", sectionList="
				+ sectionList + "]";
	}

	@Override
	public Object clone() throws CloneNotSupportedException {
		ModelDetail detail = (ModelDetail) super.clone();
		if (sectionList != null) {
			List<ModelSection> newSectionList = new ArrayList<ModelSection>();
			for (ModelSection section : sectionList) {
				newSectionList.add((ModelSection) section.clone());
			}
			detail.setSectionList(newSectionList);
		}
		return detail;
	}

	public static class ModelSection implements Cloneable {

		private long id;
		private String name;
		private int cols;
		private List<Field> fieldList;
		private int minWidth;

		public long getId() {
			return id;
		}

		public void setId(long id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public int getCols() {
			return cols;
		}

		public void setCols(int cols) {
			this.cols = cols;
		}

		public List<Field> getFieldList() {
			return fieldList;
		}

		public void setFieldList(List<Field> fieldList) {
			this.fieldList = fieldList;
		}

		public int getMinWidth() {
			return minWidth;
		}

		public void setMinWidth(int minWidth) {
			this.minWidth = minWidth;
		}

		@Override
		public Object clone() throws CloneNotSupportedException {
			ModelSection section = (ModelSection) super.clone();
			if (fieldList != null) {
				List<Field> newFieldList = new ArrayList<Field>();
				for (Field field : fieldList) {
					newFieldList.add((Field) field.clone());
				}
				section.setFieldList(newFieldList);
			}
			return section;
		}

		@Override
		public String toString() {
			return "ModelSection [id=" + id + ", name=" + name + ", cols="
					+ cols + ", fieldList=" + fieldList + ", minWidth="
					+ minWidth + "]";
		}
	}

	/**
	 * Field type:<br>
	 * 1-textfield <br>
	 * 2-combo<br>
	 * 3-checkbox<br>
	 * 4-datefield<br>
	 * 5-radiogroup <br>
	 * 6-textarea<br>
	 * 7-numberfield<br>
	 * 8-panel<br>
	 * 9-image<br>
	 * 100-blank line<br>
	 * 31-fileuploadfield <br>
	 * 32-filegrid <br>
	 **/
	public static class Field implements Cloneable {
		private long fieldId;
		private String fieldName;
		private int fieldType;
		private boolean isRequired;
		private String relatedValue;
		private List<String> values;
		private String selectedValue;
		private int cols;
		private int rows;
		private int width;
		private int height;
		private int labelWidth;
		private String defaultValue;

		public int getLabelWidth() {
			return labelWidth;
		}

		public void setLabelWidth(int labelWidth) {
			this.labelWidth = labelWidth;
		}

		public int getWidth() {
			return width;
		}

		public void setWidth(int width) {
			this.width = width;
		}

		public int getHeight() {
			return height;
		}

		public void setHeight(int height) {
			this.height = height;
		}

		public int getCols() {
			return cols;
		}

		public void setCols(int cols) {
			this.cols = cols;
		}

		public int getRows() {
			return rows;
		}

		public void setRows(int rows) {
			this.rows = rows;
		}

		public long getFieldId() {
			return fieldId;
		}

		public void setFieldId(long fieldId) {
			this.fieldId = fieldId;
		}

		public String getFieldName() {
			return fieldName;
		}

		public void setFieldName(String fieldName) {
			this.fieldName = fieldName;
		}

		public int getFieldType() {
			return fieldType;
		}

		public void setFieldType(int fieldType) {
			this.fieldType = fieldType;
		}

		public boolean isRequired() {
			return isRequired;
		}

		public void setRequired(boolean isRequired) {
			this.isRequired = isRequired;
		}

		public String getRelatedValue() {
			return relatedValue;
		}

		public void setRelatedValue(String relatedValue) {
			this.relatedValue = relatedValue;
		}

		public List<String> getValues() {
			return values;
		}

		public void setValues(List<String> values) {
			this.values = values;
		}

		public String getSelectedValue() {
			return selectedValue;
		}

		public void setSelectedValue(String selectedValue) {
			this.selectedValue = selectedValue;
		}

		public String getDefaultValue() {
			return defaultValue;
		}

		public void setDefaultValue(String defaultValue) {
			this.defaultValue = defaultValue;
		}

		@Override
		public Object clone() throws CloneNotSupportedException {
			Field field = (Field) super.clone();
			if (values != null) {
				List<String> newValues = new ArrayList<String>();
				for (String value : values) {
					newValues.add(new String(value));
				}
				field.setValues(newValues);
			}
			return field;
		}

		@Override
		public String toString() {
			return "Field [fieldId=" + fieldId + ", fieldName=" + fieldName
					+ ", fieldType=" + fieldType + ", isRequired=" + isRequired
					+ ", relatedValue=" + relatedValue + ", values=" + values
					+ ", selectedValue=" + selectedValue + ", cols=" + cols
					+ ", rows=" + rows + ", width=" + width + ", height="
					+ height + ", labelWidth=" + labelWidth + ", defaultValue="
					+ defaultValue + "]";
		}

	}
}
